Skip to content

Fix: SafeTarExtractor may silently accept truncated members when member.size metadata is incorrect - #1663

Merged
steam-bell-92 merged 1 commit into
steam-bell-92:mainfrom
Kirtan-pc:fix/accept-truncated-members
Jul 12, 2026
Merged

Fix: SafeTarExtractor may silently accept truncated members when member.size metadata is incorrect#1663
steam-bell-92 merged 1 commit into
steam-bell-92:mainfrom
Kirtan-pc:fix/accept-truncated-members

Conversation

@Kirtan-pc

Copy link
Copy Markdown
Contributor

📝 Description

Summary

Fix SafeTarExtractor._extract_file() to detect truncated file data. When a tar member's declared size metadata exceeds the actual available data, the method previously broke out of the read loop silently and renamed the incomplete temp file to the target path, allowing corrupted or partially-controlled payloads to be written to disk.

Changes

security/tar_safe.py

  • _extract_file(): Replaced the silent break with an explicit UnsafeTarError when src.read() returns empty bytes before bytes_copied reaches member.size. The exception propagates to the outer try/except block which cleans up the temp file before re-raising.

tests/test_security.py

  • test_truncated_file_detection: New test that creates a valid tar, truncates the file to cut off part of the data, and verifies that extraction raises UnsafeTarError.
    </|DSML|parameter>
    </|DSML|invoke>
    </|DSML|tool_calls>

🔗 Linked Issue

Closes #1544


📋 Contribution Checklist

  • I have verified that my files are placed in the correct directory.
  • I have tested my changes thoroughly on my local machine.
  • GSSoC 2026: I have been formally assigned to this issue and noted it above.

@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown

@Kirtan-pc is attempting to deploy a commit to the Anuj's projects Team on Vercel.

A member of the Team first needs to authorize it.

@steam-bell-92 steam-bell-92 added level:beginner gssoc:approved GSSoC 2026 approving tag type:bug Something isn't working labels Jul 12, 2026
@steam-bell-92
steam-bell-92 merged commit 8622ee3 into steam-bell-92:main Jul 12, 2026
3 of 4 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Thank you for your contribution!

Your Pull Request has been merged successfully.
Thanks again for your support! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC 2026 approving tag level:beginner type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: SafeTarExtractor may silently accept truncated members when member.size metadata is incorrect

2 participants